<template>
    <div>

 <a-upload name="file"
            :supportServerRender="true"
            :multiple="true"
            action="https://up-z2.qiniup.com/"
            :headers="headers"
            :data="formData"
            :beforeUpload="beforeUpload"
            :disabled = "allowUpload"
            :fileList="fileList"
            :remove="handleRemove"
            @change="handleChange">
    <a-button>
      <a-icon type="upload" /> 选择上传的文件
    </a-button>
  </a-upload>

    </div>
</template>
<script>
export default {
     name: "",
      props:{
        communityDID :{
          type:Number|String,
          default:''
        },
        token:{
          type:String,
          default:''
        }
      },
      data(){
          return{
            allowUpload:false,
            formData:{
              token:'',
              key:''
            },
            headers: {
              authorization: 'authorization-text',
            },
            fileList:[],
            addFile:{}
          }
      },
      methods:{
        handleRemove(file) {
          this.fileList = [];
        },
        beforeUpload(info){
          this.fileList = [...this.fileList, info];
          this.formData.key = this.communityDID + '-' +(new Date()).getTime() + '-' + info.name;
          this.formData.token = this.token;
          this.addFile.name = info.name;
          this.addFile.communityDID = this.communityDID;
          this.addFile.url = this.formData.key;
        },
        handleChange(info) {
          let fileList = [...info.fileList];
          fileList = fileList.slice(-2);
          fileList = fileList.map(file => {
            if (file.response) {
          
              file.url = file.response.url;
              console.log('上传成功','http://q1rhut7gn.bkt.clouddn.com'+file.response.key)
              this.$emit('fileUrlMethod',this.addFile)
            }
            return file;
          });
          this.fileList = fileList;
       
        },
      },
      mounted(){

      }

}
</script>


<style scoped>

</style>